CMU 15-112 Summer 2019: Fundamentals of Programming and Computer Science
Homework 2 (Due Thurs 23-May, at 5pm)




  1. nthSteezyPrime [60 pts]
    Write the function nthSteezyPrime(n) that takes in a number n, and returns the nthSteezyPrime. A steezy prime is any positive prime number with the following two properties:
    • No two consecutive digits are the same.
    • All rotations of the number are also primes that satisfy the consecutive digits property mentioned above. In this case, rotation refers to cycling the digits of a number; for example, the rotations of 1234 are 1234, 2341, 3412, and 4123.
    To find the nth steezy prime, you'll need to write isPrime (which you can use from the notes) and three other functions:

    1. rotateNumber [20 pts]
      This function takes a non-negative integer number, x, and rotates that number's digits by one place. This would turn the number 1234 to 4123.

    2. isSteezyPrime [30 pts]
      This function takes a non-negative integer number, x, and determines whether that number is a steezy prime. To do this, you'll need to check whether every rotation of the number is a prime that satisfies the consecutive digits property mentioned above.

    3. nthSteezyPrime [10 pts]
      This function takes a non-negative integer number n, and returns the nth steezy prime.


  2. carrylessAdd [35pts]
    First, read the first page (page 44) from here about Carryless Arithmetic. Fun! Then, write the function carrylessAdd(x, y) that takes two non-negative integers x and y and returns their carryless sum. As the paper demonstrates, carrylessAdd(785, 376) returns 51.

  3. vowelCount(s) [5pts]
    Write the function vowelCount(s), that takes a string s, and returns the number of vowels in s, ignoring case, so "A" and "a" are both vowels. The vowels are "a", "e", "i", "o", and "u". So, for example: vowelCount("Abc def!!! a? yzyzyz!") returns 3 (two a's and one e).